﻿@using OJS.Common.Models
@model IList<OJS.Web.ViewModels.Submission.SubmissionViewModel>

@{
    ViewBag.Title = "Последно изпратени решения";
}

<ol class="breadcrumb">
    <li><a href="/">Начало</a></li>
    <li class="active">Решения</li>
</ol>

<h1>@ViewBag.Title</h1>
<table class="table table-striped table-hover"> @* TODO: Vertical center rows *@
    <thead>
        <tr>
            <th class="col-md-1 text-primary">
                №
            </th>
            <th class="col-md-4 text-primary">
                Изпратено от
            </th>
            <th class="col-md-3 text-primary">
                Задача
            </th>
            <th class="col-md-4 text-primary">
                Резултат
            </th>
        </tr>
    </thead>
    <tbody>
        @for (int i = 0; i < Model.Count(); i++)
        {
            <tr>
                <td>
                    <strong>@Model[i].Id</strong>
                </td>
                <td>
                    <div>
                        <strong><a href="/Users/@Model[i].ParticipantName">@Model[i].ParticipantName</a></strong>
                    </div>
                    <div>
                        <small><span>@Model[i].SubmitedOn</span></small>
                    </div>
                </td>
                <td>
                    <div>
                        <strong class="text-primary">@Model[i].ProblemName</strong>
                    </div>
                    <div>
                        <small>@Model[i].Contest</small>
                    </div>
                </td>
                <td>
                        <div>
                        @{
                            var tests = Model[i].TestResults.ToList();

                            if (!Model[i].Processed)
                            {
                                <span class="glyphicon glyphicon-time text-primary" title="Loading..."></span>
                                <strong class="text-primary"> Обработва се...</strong>
                            }
                            else if (!Model[i].IsCompiledSuccessfully)
                            {
                                <span class="glyphicon glyphicon-remove text-danger" title="Compilation failed"></span>
                                <strong class="text-danger"> Compilation failed!</strong>
                            }
                            else
                            {
                                <div>
                                    <strong class="text-primary">@Model[i].Points / @Model[i].ProblemMaximumPoints</strong>
                                    <small>@string.Format("{0:F2} MB", Model[i].MaxUsedMemory / 1024.0 / 1024.0) | @string.Format("{0:F3} sec.", (decimal)Model[i].MaxUsedTime / 1000) | @Model[i].SubmissionType</small>
                                </div>
                                for (int j = 0; j < tests.Count; j++)
                                {
                                    if (tests[j].IsTrialTest)
                                    {
                                        continue;
                                    }
                    
                                    switch (tests[j].ExecutionResult)
                                    {
                                        case TestRunResultType.CorrectAnswer:<span class="glyphicon glyphicon-ok text-success" title="Correct answer"></span>break;
                                        case TestRunResultType.WrongAnswer:<span class="glyphicon glyphicon-remove text-danger" title="Wrong answer"></span>break;
                                        case TestRunResultType.TimeLimit:<span class="glyphicon glyphicon-time text-danger" title="Time limit"></span>break;
                                        case TestRunResultType.MemoryLimit:<span class="glyphicon glyphicon-hdd text-danger" title="Memory limit"></span>break;
                                        case TestRunResultType.RunTimeError:<span class="glyphicon glyphicon-asterisk text-danger" title="Run-time error"></span>break;
                                    }
                                }
                            }

                        }
                    </div>
                </td>
            </tr>
        }
    </tbody>
</table>
